/*
 * Implementacion del Analizador Lexico para CUP.
 * 
 * @ Project: Compiler
 * @ File Name: ParsingScanner.java
 */
package cml.parsing;

import java_cup.runtime.Symbol;
import cml.TokenType;
import cml.scanning.Scanner;

public class ParsingScanner implements java_cup.runtime.Scanner {

	private Scanner scanner;
	
	/*
	 * Constructor de la clase.
	 * 
	 * @param	s	el analizador lexico original
	 */
	public ParsingScanner(Scanner s) {
	
		this.scanner = s;
	}
	
	/*
	 * Devuelve el siguiente <code>token</code> encontrado.
	 * 
	 * @return	<code>token</code> encontrado
	 */
	@Override
	public Symbol next_token() throws Exception {		

		
		TokenType t = this.scanner.getToken();
		
		int ln = this.scanner.getCurrentLine();
		
		switch(t){

			case IF: return new Symbol(sym.IF, ln, ln, this.scanner.getTokenString());				
			case ELSE: return new Symbol(sym.ELSE, ln, ln, this.scanner.getTokenString());
			case FOR: return new Symbol(sym.FOR, ln, ln, this.scanner.getTokenString());
			case WHILE: return new Symbol(sym.WHILE, ln, ln, this.scanner.getTokenString());
			case RETURN: return new Symbol(sym.RETURN, ln, ln, this.scanner.getTokenString());
			case VOID: return new Symbol(sym.VOID, ln, ln, this.scanner.getTokenString());
			case INT: return new Symbol(sym.INT, ln, ln, this.scanner.getTokenString());
			case DEC: return new Symbol(sym.DEC, ln, ln, this.scanner.getTokenString());
			case BOOLEAN: return new Symbol(sym.BOOLEAN, ln, ln, this.scanner.getTokenString());
			case TEXT: return new Symbol(sym.TEXT, ln, ln, this.scanner.getTokenString());
			case ID: return new Symbol(sym.ID, ln, ln, this.scanner.getTokenString());
			case NUMINT: return new Symbol(sym.NUMINT, ln, ln, new Integer(Integer.parseInt(this.scanner.getTokenString())));
			case NUMDEC: return new Symbol(sym.NUMDEC, ln, ln, new Double(Double.parseDouble(this.scanner.getTokenString())));
			case TEXTLITERAL: return new Symbol(sym.TEXTLITERAL, ln, ln, this.scanner.getTokenString());
			case TRUE: return new Symbol(sym.TRUE, ln, ln, new Boolean(true));
			case FALSE: return new Symbol(sym.FALSE, ln, ln, new Boolean(false));
			case PLUS: return new Symbol(sym.PLUS, ln, ln, this.scanner.getTokenString());
			case MINUS: return new Symbol(sym.MINUS, ln, ln, this.scanner.getTokenString());
			case TIMES: return new Symbol(sym.TIMES, ln, ln, this.scanner.getTokenString());
			case OVER: return new Symbol(sym.OVER, ln, ln, this.scanner.getTokenString());
			case EQ: return new Symbol(sym.EQ, ln, ln, this.scanner.getTokenString());
			case NEQ: return new Symbol(sym.NEQ, ln, ln, this.scanner.getTokenString());
			case LT: return new Symbol(sym.LT, ln, ln, this.scanner.getTokenString());
			case GT: return new Symbol(sym.GT, ln, ln, this.scanner.getTokenString());
			case LTEQ: return new Symbol(sym.LTEQ, ln, ln, this.scanner.getTokenString());
			case GTEQ: return new Symbol(sym.GTEQ, ln, ln, this.scanner.getTokenString());
			case ASSIGN: return new Symbol(sym.ASSIGN, ln, ln, this.scanner.getTokenString());
			case COMMA: return new Symbol(sym.COMMA, ln, ln, this.scanner.getTokenString());
			case SEMICOLON: return new Symbol(sym.SEMICOLON, ln, ln, this.scanner.getTokenString());
			case LPAREN: return new Symbol(sym.LPAREN, ln, ln, this.scanner.getTokenString());
			case RPAREN: return new Symbol(sym.RPAREN, ln, ln, this.scanner.getTokenString());
			case LBRAK: return new Symbol(sym.LBRAK, ln, ln, this.scanner.getTokenString());
			case RBRAK: return new Symbol(sym.RBRAK, ln, ln, this.scanner.getTokenString());
			case LBRACE: return new Symbol(sym.LBRACE, ln, ln, this.scanner.getTokenString());
			case RBRACE: return new Symbol(sym.RBRACE, ln, ln, this.scanner.getTokenString());
			case ENDFILE: return new Symbol(sym.EOF);
			default: return null;
		}
	}
}
